package com.ncp.servlet.product;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ncp.model.biz.product.ManageBackstageProductBiz;
import com.ncp.model.biz.product.ManageFrontProductBiz;
import com.ncp.model.dao.DB;
import com.ncp.model.entity.product.ProductAllInfoBean;
import com.ncp.model.entity.product.ProductDetailBean;
import com.ncp.model.entity.product.ProductSortBean;

public class ManagerBasicDelServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		boolean b1 =false,b2=false;
		String type = request.getParameter("type");
		 ManageBackstageProductBiz mbpb = new ManageBackstageProductBiz();
		 ManageFrontProductBiz mfpb = new ManageFrontProductBiz();
		 int ProductID = Integer.parseInt(request.getParameter("ProductID"));
		if(type.equals("del")){
			
			 List<ProductAllInfoBean> list = mfpb.getProductAllInfoBean(ProductID);
			 ProductAllInfoBean pab = list.get(0);
			 b1 = mbpb.setProductBasicLoad(pab);
			 
		     b2 = mbpb.setProductBasicDel(ProductID);
			if(b1==true&&b2==true){
				String pages = "ManagerShowBasicServlet?type=del&PageNow=1";
				request.setAttribute("pages",pages);
				request.getRequestDispatcher("pages/admin/product/suc.jsp").forward(request,response);
				
			}else{
				
				request.getRequestDispatcher("pages/admin/product/err.jsp").forward(request,response);
			}
		
		}
		else if(type.equals("update")){
			
		

			
			List<ProductAllInfoBean> listall = mfpb.getProductAllInfoBean(ProductID);
			
		    List<ProductSortBean> listparent =  mfpb.getProductSort("select * from PRODUCTSORT where isover=0");
		    ProductAllInfoBean pab = listall.get(0);
		    String ProductSortName = mfpb.getProductSortName(pab.getProductSortID());
		    request.setAttribute("ProductSortName", ProductSortName);
		    request.setAttribute("listparent", listparent);
			request.setAttribute("listall",listall);
			request.getRequestDispatcher("pages/admin/product/detailupdate.jsp").forward(request,response);

		}
		else if(type.equals("delsort")){
			b2 =  mbpb.setProductSortDel(ProductID);
			if(b2==true){
				String pages = "ManagerShowSortServlet";
				request.setAttribute("pages",pages);
				request.getRequestDispatcher("pages/admin/product/suc.jsp").forward(request,response);
				
			}else{
				
				request.getRequestDispatcher("pages/admin/product/err.jsp").forward(request,response);
			}
		
		}
	}

}
